
import request from '../utils/request'

// 添加学员
interface RuleForm {
    name: string;
    sex: string;
    cardId: string;
    tel: string;
    avatar?: string;
    schoolName: string;
    isIndigen: string;
    type: string;
    carType: string;
    Regtime: string;
    referrer?: string;
    address: string;
    content?: string;
    coach1?: string;
    coach2?: string;
}
interface MoneyType {
    ArrearageState: string;
    MoneyState: string;
}
export const StuAdd = (stuobj: RuleForm) => {
    return request.post("classes/student", stuobj)
}



// 详情页面查询
export const StuGet = (id: string) => {
    return request.get(`classes/student/${id}`)
}
// 按条件查询

// 查询数据
interface SeachType {
    name: string;
    cardId: string;
    tel: string;
}
export const StuCondGet = ({ name, cardId, tel }: SeachType) => {
    let where = {} as SeachType
    if (name) {
        where.name = name
    }
    if (cardId) {
        where.cardId = cardId
    }
    if (tel) {
        where.tel = tel
    }
    return request.get("classes/student", {
        params: {
            limit: 10,
            skip: 0,
            where
        }
    })
}

interface TrainStateType {
    trainState: string
}
// 修改学员数据
export const StuRenewalPut = (id: string, update: RuleForm | MoneyType | TrainStateType) => {
    return request.put(`classes/student/${id}`, update)
}

// 查询所有数据导出为Excel
export const StuAllGet = () => {
    return request.get("classes/student")
}

// 查询校区信息
export const SchoolNameGet = () => {
    return request.get("classes/school")
}
// 批量修改学员状态数据
export const StuStatePost = (obj: any) => {
    let { studentId, state, stateTime } = obj
    let requests = studentId.map((id: string) => {
        return {
            method: "PUT",
            path: `/1.1/classes/student/${id}`,
            body: {
                state: state,
                stateTime: stateTime
            }
        }
    })
    return request.post("batch", { requests })
}

// 批量修改学员科目数据
export const StuSubjectPost = (obj: any) => {
    let { studentId,
        subject,
        subjectState,
        SubjectTime,
        subjectRemark, } = obj
    let requests = studentId.map((id: string) => {
        return {
            method: "PUT",
            path: `/1.1/classes/student/${id}`,
            body: {
                subject,
                subjectState,
                SubjectTime,
                subjectRemark
            }
        }
    })
    return request.post("batch", { requests })
}

//获取车型
export const CarTypeGet = () => {
    return request.get("classes/cartype")
}



// 查询学员练车记录
export const StuTranGet = (id?: string) => {
    return request.get("classes/tranRecord", {
        params: {
            limit: 10,
            skip: 0,
            where: {
                stuId: id
            }
        }
    })
}


// 分页条差练车记录表数据
export const StuTeanGet = (page = 1, num: number, id: string) => {
    let skip = (page - 1) * num
    return request.get("classes/student", {
        params: {
            limit: num,
            skip,
            count: 1,
            where: {
                stuId: id
            }
        }
    })
}

// 删除练车记录
export const TranDeletet = (id: string) => {
    return request.delete(`classes/tranRecord/${id}`)
}
// 核对练车记录
export const TranPut = (id: string, data: any) => {
    return request.put(`classes/tranRecord/${id}`, data)
}


// 查询学员缴费记录
export const StuMoney = (id: string | string[]) => {
    return request.get("classes/expenditure", {
        params: {
            limit: 10,
            skip: 0,
            count: 1,
            where: {
                studentId: id
            }
        }
    })
}

//分页条查询数据
export const StuMoneyGet = (page = 1, num: number, id: string) => {
    let skip = (page - 1) * num
    return request.get("classes/expenditure", {
        params: {
            limit: num,
            skip,
            count: 1,
            where: {
                studentId: id
            }
        }
    })
}

// 删除学员缴费记录
export const StuMoneyDel = (id: string) => {
    return request.delete(`classes/expenditure/${id}`)
}

// 修改学员缴费记录
export const StuMoneyPut = (id: string, mondata: any) => {
    return request.put(`classes/expenditure/${id}`, mondata)
}

// 查询收入项目名
export const StuOutMoney = () => {
    return request.get("classes/financial")
}

// 查询考试步骤
export const StuExamGet = (id?: string) => {
    let subjectid = id ? id : "0-0"
    console.log(subjectid)
    return request.get("classes/process", {
        params: {
            where: {
                parentId: subjectid
            }
        }
    })
}


